/***************************************************************************
 *   Copyright (C) 2004 by cyril dupuit                                    *
 *   cyrildupuit@hotmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

//*****************************************************************************
// Nom du module : Serial.h
// Description : Gestion des ports series
//*****************************************************************************
 
// Historique :
// 28/10/04 : Creation du module V1.0  

#ifndef SERIAL_HEADER
#define SERIAL_HEADER

//*****************************************************************************
// Definition des equivalences :
//*****************************************************************************

#define SERIAL_BAUDRATE_MAX 115200L

/* The offsets of UART registers.  */
#define UART_TX         0
#define UART_RX         0
#define UART_DLL        0
#define UART_IER        1
#define UART_DLH        1
#define UART_IIR        2
#define UART_FCR        2
#define UART_LCR        3
#define UART_MCR        4
#define UART_LSR        5
#define UART_MSR        6
#define UART_SR         7

/* For LSR bits.  */
#define UART_DATA_READY         0x01
#define UART_EMPTY_TRANSMITTER  0x20

/* The type of parity.  */
#define UART_NO_PARITY          0x00
#define UART_ODD_PARITY         0x08
#define UART_EVEN_PARITY        0x18

/* The type of word length.  */
#define UART_5BITS_WORD 0x00
#define UART_6BITS_WORD 0x01
#define UART_7BITS_WORD 0x02
#define UART_8BITS_WORD 0x03

/* The type of the length of stop bit.  */
#define UART_1_STOP_BIT         0x00
#define UART_2_STOP_BITS        0x04

/* the switch of DLAB.  */
#define UART_DLAB               0x80

/* Enable the FIFO.  */
#define UART_ENABLE_FIFO        0xC7

/* Turn on DTR, RTS, and OUT2.  */
#define UART_ENABLE_MODEM       0x0B

//*****************************************************************************
// But de la fonction : Initialiser le port serie
// Entrees :
//	Unit : Numero du port a selectionner
//	Speed : Debit en bauds
//	WordLen : Taille d'un paquet de donne
//	Parity : Parite paire, impaire ou aucune
//	StopBitLen : Nombre de bits de stop (1, 1.5, 2)
// Parametre retourne : ERROR si le numero de port est incorrecte ou si le 
//debit est superieur a SERIAL_BAUDRATE_MAX, TRUE sinon
//*****************************************************************************
Status_t SerialInit(unsigned short Unit, unsigned long Speed, int WordLen, int Parity, int StopBitLen);

//*****************************************************************************
// But de la procedure : Emettre un caractere sur la ligne serie
// Entree :
//	C : Caractere a envoyer sur la ligne
// Sortie : Aucune
//*****************************************************************************
void SerialPutchar(char C);

//*****************************************************************************
// But de la fonction : Recevoir un caractere par la ligne serie
// Entree : Aucune
// Parametre retourne : Caractere lu
//*****************************************************************************
char SerialGetchar (void);

//*****************************************************************************
// But de la fonction : Tester si un caractere se trouve dans le buffer de
// reception
// Entree : Aucune
// Parametre retourne : TRUE si aucun caractere recu, FALSE sinon
//*****************************************************************************
Status_t SerialIsReady(void);

//*****************************************************************************

#endif
